import { defineConfig } from 'vite';
import { resolve } from 'node:path';
import path from 'path';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig({
	plugins: [
		vue(),
		AutoImport({
			resolvers: [
				// 自动导入element-plus组件
				ElementPlusResolver()
			]
		}),
		Components({
			resolvers: [
				// 自动导入element-plus组件
				ElementPlusResolver()
			]
		})
	],
	resolve: {
		alias: [
			{ find: '@', replacement: path.resolve(__dirname, 'src') },
			{ find: 'views', replacement: resolve(__dirname, 'src/views') }
		]
	},
	server: {
		open: true,
		port: 9527,
		hmr: true, // 开启热更新
		proxy: {
			'/XGgateway/': {
				target: 'http://192.168.15.27:2050',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/XGgateway/, '')
			}
		},
		// 关闭主机检查，使微应用可以被 fetch
		disableHostCheck: true,
		// 配置跨域请求头，解决开发环境的跨域问题
		headers: {
			'Access-Control-Allow-Origin': '*'
		}
	}
});
